/*********************************
 * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
 * Copyright (c) 2012 NVision Group, Inc. All rights reserved.
 *
 * GroupOperationTabView.java 22.08.2012 17:32:16
 *********************************/
package ru.kruzhki.client.gwtp;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ru.kruzhki.client.gwt.Maskable;
import ru.kruzhki.client.gwt.MaskableView;
import ru.kruzhki.client.gwt.Maskables;

import com.google.gwt.user.client.ui.Widget;
import com.gwtplatform.mvp.client.ViewImpl;

/**
 * 
 * @author starasov
 *
 */
public abstract class AbstractView<W extends Widget> extends ViewImpl implements MaskableView{

    protected final Logger log = LoggerFactory.getLogger(this.getClass().getName());
	private W widget;  
    
	@Override
    public final W asWidget() {
        if(widget==null){
            widget=createWidget();
            log.debug("View widget has been created: {}",widget);
        }
        return widget;
    }

	
    /**
     * @return
     */
    protected abstract W createWidget();

    protected Maskable getMaskable(){
        return Maskables.getMockMaskable();
    }
    
    
    @Override
    public void mask() {
        getMaskable().mask();
    }

    @Override
    public void mask(String message) {
        getMaskable().mask(message);
    }

    @Override
    public void unmask() {
        getMaskable().unmask();
    }
}
